package com.ls.server.controller;

import com.ls.server.dto.McpQueryDTO;
import com.ls.server.dto.McpServiceDTO;
import com.ls.server.service.McpServiceService;
import com.ls.server.vo.McpServiceVO;
import com.ls.server.vo.PageResult;
import com.ls.server.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * MCP服务控制器
 */
@RestController
@RequestMapping("/mcp/service")
public class McpServiceController {

    private final McpServiceService mcpServiceService;

    public McpServiceController(McpServiceService mcpServiceService) {
        this.mcpServiceService = mcpServiceService;
    }

    /**
     * 分页查询MCP服务
     * @param queryDTO 查询条件
     * @return 分页结果
     */
    @PostMapping("/page")
    public Result<PageResult<McpServiceVO>> page(@RequestBody McpQueryDTO queryDTO) {
        return Result.success(mcpServiceService.page(queryDTO));
    }

    /**
     * 查询所有可用的MCP服务
     * @return MCP服务列表
     */
    @GetMapping("/list")
    public Result<List<McpServiceVO>> listAvailable() {
        return Result.success(mcpServiceService.listEnabledServices());
    }

    /**
     * 根据ID查询MCP服务
     * @param id MCP服务ID
     * @return MCP服务信息
     */
    @GetMapping("/get/{id}")
    public Result<McpServiceVO> getById(@PathVariable Long id) {
        return Result.success(mcpServiceService.getServiceById(id));
    }

    /**
     * 新增MCP服务
     * @param dto MCP服务信息
     * @return 操作结果
     */
    @PostMapping
    public Result<Boolean> save(@RequestBody McpServiceDTO dto) {
        return Result.success(mcpServiceService.createService(dto));
    }

    /**
     * 修改MCP服务
     * @param dto MCP服务信息
     * @return 操作结果
     */
    @PutMapping
    public Result<Boolean> update(@RequestBody McpServiceDTO dto) {
        return Result.success(mcpServiceService.updateService(dto));
    }

    /**
     * 删除MCP服务
     * @param id MCP服务ID
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(mcpServiceService.deleteService(id));
    }

    /**
     * 更新MCP服务状态
     * @param id MCP服务ID
     * @param enabled 是否启用
     * @return 操作结果
     */
    @PutMapping("/status/{id}/{enabled}")
    public Result<Boolean> updateStatus(@PathVariable Long id, @PathVariable Boolean enabled) {
        return Result.success(mcpServiceService.updateStatus(id, enabled));
    }
} 